import requests
import json

sql = """
select dt.type_code,
       dt.type_name,
       dt.icon,
       dt.classifier, 
       dck.key_code,
       dck.key_name,
       dck.key_order,
       dck.default_value,
       dck.value_type
from xi_test_datasource_type dt
       join xi_test_datasource_config_key dck on dt.type_code = dck.datasource_type
"""

if __name__ == '__main__':
    url = "http://linkis-test:9001/api/rest_j/v1/entrance/submit"
    headers = {
        'Content-Type': 'application/json',
        'Token-Code': 'dss-AUTH',
        'Token-User': 'linkis'
    }

    requestBody = {
        "executionContent": {
            "code": sql,  # 要查询的 SQL
            "runType": "jdbc"
        },
        "params": {
            "variable": {},
            "configuration": {
                "startup": {},
                "runtime": {
                    # linkis 中配置的数据源
                    "wds.linkis.engine.runtime.datasource": "oceanbase_test"
                }
            }
        },
        "source": {
            "scriptPath": ""
        },
        "labels": {
            "engineType": "jdbc-4",
            "userCreator": "linkis-IDE"
        }
    }
    res = requests.post(url=url, headers=headers, data=json.dumps(requestBody))
    print(res.text)
